import {ImagePreview} from 'vant';

export const getImageInfo = (imgUrl = '') => {
    return new Promise(resolve => {
        const xhr = new XMLHttpRequest()
        window.URL = window.URL || window.webkitURL
        xhr.open('get', imgUrl, true)
        xhr.responseType = 'blob'
        xhr.send()
        xhr.onload = function (event) {
            const res: any = event.target
            const blobObj = res.response
            const fileReader = new FileReader()
            fileReader.readAsDataURL(blobObj)
            fileReader.onloadend = function (e) {
                let base64Url = e.target?.result
                let blobUrl = URL.createObjectURL(blobObj)
                if (res.status !== 200) {
                    base64Url = ''
                    blobUrl = ''
                }
                resolve({
                    base64Url,
                    blobUrl
                })
            }
        }
    })
}
export const showImagePreview = (imgUrl: string | Array<string>) => {
    if (typeof imgUrl === "string") {
        ImagePreview([imgUrl])
    } else {
        ImagePreview(imgUrl)
    }
}
